<?php

namespace Yi\Permission\Http\Middleware;

// use Closure;
// use Tymon\JWTAuth\Exceptions\JWTException;
// use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;
// use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Illuminate\Support\Facades\Log;
// use Illuminate\Support\Facades\Config;


// use Tymon\JWTAuth\Facades\JWTAuth;




use Closure;
// use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Support\Facades\Auth;


class BackendAuthMiddleware
{
    protected $auth;

    public function __construct()
    {
        $this->auth = auth('backend');
    }

    public function handle($request, Closure $next, $permissions = null)
    {

        $user = $this->auth->user(); #当前用户
        Log::debug("BackendAuthMiddleware_permissions————————————————————————————", [$permissions]);
        if ($permissions !== "any") {
            $permissionGuardList = explode("|", $permissions);
        }

        if ($user) {
            return $next($request);
        } else {
            $data['message'] = '鉴权失败';

            return  fail($code = 401, $errmsg = '鉴权失败', $data = [], 401);
            // return success($data, 401);
        }

        // return success('Unauthorized.', 401);
    }
}
